/// @tags: 01Trie
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 5e5 + 2e4 + 6e3;

struct Node {
  int ch[2], sum;
  bool tag, cnt;
} tr[N * 32];

struct Edge {
  int v, nxt;
} e[N];

int e_cnt, cnt;
int heads[N], root[N];
LL ans;

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

inline void pushup(int x) {
  int ls = tr[x].ch[0], rs = tr[x].ch[1];
  tr[x].cnt = tr[x].tag ^ tr[ls].cnt ^ tr[rs].cnt;
  tr[x].sum = ((tr[ls].sum << 1) ^ (tr[rs].sum << 1)) | tr[rs].cnt;
}

void insert(int &rt, int x) {
  if (rt == 0) rt = ++cnt;
  if (x == 0) return tr[rt].cnt ^= 1, tr[rt].tag ^= true, void();
  insert(tr[rt].ch[x & 1], x >> 1);
  pushup(rt);
}

void merge(int &x, int y) {
  if ((x && y) == false) return void(x |= y);
  tr[x].cnt ^= tr[y].cnt;
  tr[x].sum ^= tr[y].sum;
  tr[x].tag ^= tr[y].tag;
  merge(tr[x].ch[0], tr[y].ch[0]);
  merge(tr[x].ch[1], tr[y].ch[1]);
}

void modify(int x) {
  if (x == 0) return;
  swap(tr[x].ch[0], tr[x].ch[1]);
  if (tr[x].tag && tr[x].ch[1] == 0) tr[x].ch[1] = ++cnt;
  int rs = tr[x].ch[1];
  tr[rs].cnt ^= tr[x].tag, tr[rs].tag ^= tr[x].tag, tr[x].tag = 0;
  modify(tr[x].ch[0]);
  pushup(x);
}

void solve(int u) {
  for (int i = heads[u], v; i; i = e[i].nxt) {
    solve(v = e[i].v);
    modify(root[v]);
    merge(root[u], root[v]);
  }
  ans += tr[root[u]].sum;
}

inline int main() {
  int n;
  cin >> n;
  for (int i = 1, v; i <= n; ++i) cin >> v, insert(root[i], v);
  for (int i = 2, p; i <= n; ++i) cin >> p, add(p, i);
  solve(1);
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P6623 [省选联考 2020 A 卷] 树.in", "r", stdin);
  freopen("P6623 [省选联考 2020 A 卷] 树.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
